const TagDao = require('../dao/tag')
const ValidatorTag = require('../validators/tag');
const ok = require('../core/response-shortcut');

class tagController {
    /**
     * 创建Tag
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async createTag(ctx) {
        // 接收客户端参数
        let req = ctx.request.body;

        //验证器,如果验证不通过,直接在验证器里报错
        await ValidatorTag.createTag(req)

        //验证通过,就操作数据库
        //创建Tag sql
        await TagDao.createTag(req);
        ctx.response.status = 200;
        ctx.body = ok.success()
    }


    /**
     * 获取某个标签详情
     * @param tagId
     * @returns {Promise.<void>}
     */
    static async getTag(ctx) {
        let tagId = ctx.params.tagId
        await ValidatorTag.getTag(tagId)
        let data = await TagDao.getTag(tagId);
        ctx.response.status = 200;
        ctx.body = ok.json(data)
    }



}

module.exports = tagController